package com.mresources.resources.handler.impl;

import com.mresources.common.dto.bo.UploadFileBo;
import com.mresources.common.dto.vo.FileListVO;
import com.mresources.common.dto.vo.UploadFileVO;
import com.mresources.common.utils.FileUtils;

import java.io.File;
import java.io.InputStream;
import java.util.List;

public class DefaultFileHandler extends AbstractFileHandler {
    public DefaultFileHandler() {
    }

    public DefaultFileHandler(String name) {
        this.name = name;
    }
    @Override
    public List<FileListVO> listDirectory(String userSeq, String directory) {
        return null;
    }

    @Override
    public List<FileListVO> listDirectory(String userSeq, String directory, List<String> filters) {
        return null;
    }

    @Override
    public UploadFileVO createDirectory(String userSeq, String parentDir, String newDir) {
        return null;
    }

    @Override
    public UploadFileVO deleteDirectory(String userSeq, String directory) {
        return null;
    }

    @Override
    public UploadFileVO moveDirectory(String userSeq, String directory) {
        return null;
    }

    @Override
    public UploadFileVO renameDirectory(String userSeq, String directory) {
        return null;
    }

    @Override
    public UploadFileVO createFile(String userSeq, String directory, UploadFileBo fileBo) {
        UploadFileVO fileVO = UploadFileVO.builder().uploaded(false).skipped(false).build();
        String filePath = directory + fileBo.getFilename();
        File file = new File(filePath);
        if (!file.exists()) {
            FileUtils.createFile(filePath, fileBo);
        }
        return fileVO;
    }

    @Override
    public UploadFileVO fileAppend(String userSeq, String directory, UploadFileBo file, InputStream content) {
        UploadFileVO fileVO = UploadFileVO.builder().uploaded(true).skipped(false).build();
        if (content != null) {
            fileVO.setUploaded(true);
            String filePath = directory + file.getFilename();
            FileUtils.writeFile(filePath, file, content);
        }
        return fileVO;
    }

    @Override
    public UploadFileVO deleteFile(String userSeq, String directory, UploadFileBo file) {
        return null;
    }

    @Override
    public UploadFileVO moveFile(String userSeq, String directory, UploadFileBo file) {
        return null;
    }

    @Override
    public UploadFileVO renameFile(String userSeq, String directory, UploadFileBo file) {
        return null;
    }
}
